package RunableClass.useClass;


import RunableClass.useClass.ReadNews;
import RunableSt.connect;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.sql.SQLException;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Anatomy
 */
public  class setporttable { 
   //  String[] Col1 = {"วันที่และเวลา","ชื่อบริษัท","เรื่อง"};
    int count=1;
       //DefaultTableModel model=new DefaultTableModel(Col1,0);
 
    
   String filex;
    
    //Here we get the actual size
  


    public void table(){
      ReadNews RN=  new ReadNews();
        //  DefaultTableModel model=new DefaultTableModel(Col1,0);
     //File file = new File(File);
 //    long fileSize = file.length();
     //     if(fileSize>0){

       
       // model.addColumn("sa",new String [] {"ID", "Producto", "Cantidad", "Precio"});
        
       
     // NewJFrame.jTable1.setModel(model);
       
           
        try {
            RN.readFromFile(filex,"");
        } catch (SQLException ex) {
        }
             
                  for(int l=0;l<ReadNews.lst.length;l++){
                     // if(lst[l] != null){
                          if(l==RN.countx){
                             break;
                          } 
                       connect a=   new connect();
                      String sqlsec="SELECT * FROM `stock_news` Where (DateTime='"+ReadNews.lst[l].get(1).toString()+" "+ReadNews.lst[l].get(2).toString()+"' AND (Company='"+ReadNews.lst[l].get(3).toString()+"' And Title='"+ReadNews.lst[l].get(4).toString()+"'))";
                       // System.out.println(sqlsec);
                      try {
                a.rs= a.stmt.executeQuery(sqlsec);
                a.rs.next();
                 //  System.out.println(a.rs.getRow() +"---->");
                if(a.rs.getRow()<=0){
                     String x[]={ReadNews.lst[l].get(1).toString()+"-"+ReadNews.lst[l].get(2).toString(),ReadNews.lst[l].get(3).toString(),ReadNews.lst[l].get(4).toString()};
                        String sql="INSERT INTO `stock_news` ("+
                               
                                "`DateTime` ,"+
                                "`Company` ,"+
                                "`Title` ,"+
                                "Link"+
                               " )"+
                                "VALUES ("+
                               "  '"+ReadNews.lst[l].get(1).toString()+" "+ReadNews.lst[l].get(2).toString()+"', '"+ReadNews.lst[l].get(3).toString()+"', '"+ReadNews.lst[l].get(4).toString()+"','"+ReadNews.lst[l].get(5).toString()+"'"+
                                ");";
            try {
                a.stmt.executeUpdate(sql);
            } catch (SQLException ex) {
            }
                        
                        a.CloseDB(); 
                    //    model.addRow(x);
                }
            } catch (SQLException ex) {
            }
                      
                     
                      
                      //System.out.println(ReadNews.lst[l].get(3).toString());
                       // String x[]={ReadNews.lst[l].get(3).toString()};
                         // model.addRow(x); 
                     // String[]  socrates = { "Socrates", "", "469-399 B.C." };
                         
                     
                     // }
                 // System.out.println((char)70); 
                  //System.out.print(sym[l]+"@");
              }
                //  javax.swing.JOptionPane.showMessageDialog(null,count);
                 // NewsModule.jLabel2.setText(String.valueOf(count));
      count++;
              //  System.out.println("Download Complete");
            
          }
  //  }
  public  setporttable(String file){
           this.filex=file;
      }
 
    
    
    
}
